package zhihuilan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import zhihuilan.dto.MyStaffShopGoodsDto;
import zhihuilan.dto.WxMiniPageDto;
import zhihuilan.entity.MyCircle;
import zhihuilan.entity.MyStaffShop;
import zhihuilan.entity.MyStaffShopGoods;
import zhihuilan.params.query.MySearchQueryParam;

import java.util.List;


@Mapper
public interface MyStaffShopGoodsMapper extends BaseMapper<MyStaffShopGoods> {
    @Select({" <script> select a.*,(6371 * acos(  cos(radians(b.lat)) * cos(radians(#{lat})) *  cos(radians(b.lng) - radians(#{lng})) +   sin(radians(b.lat)) * sin(radians(#{lat})) ))*1000  distance " +
            " from my_staff_shop_goods a " +
            " left join my_staff_shop b on a.staff_id = b.staff_id \n" +
            "<where>"+
            " and a.status =1 \n" +
            " and a.shopId &gt; 0 \n" +
            " <if test='keyword != null and keyword != \"\"'> " +
            "  and( a.remark like concat('%',#{keyword},'%') \n" +
            "  or a.name like concat('%',#{keyword},'%') \n" +
            " </if> " +
            " <if test='orConditions != null and orConditions != \"\"'> " +
            "  ${orConditions} )\n" +
            " </if> " +
            " and (6371 * acos(  cos(radians(b.lat)) * cos(radians(#{lat})) *  cos(radians(b.lng) - radians(#{lng})) +   sin(radians(b.lat)) * sin(radians(#{lat})) )) &lt; 500 \n" +
            "</where>"+
            " order by distance asc "+
            " LIMIT #{page},#{pageSize} " +
            " </script>"})
    List<MyStaffShopGoods> selectMyStaffShopGoodsPage(@Param("page") Long page, @Param("pageSize") Long pageSize, @Param("lat") Double lat, @Param("lng") Double lng, @Param("keyword") String keyword,@Param("orConditions") String orConditions);

    @Select({" <script> select count(*) " +
            " from my_staff_shop_goods a " +
            " left join my_staff_shop b on a.staff_id = b.staff_id \n" +
            " where a.status =1 \n" +
            " and a.shopId &gt; 0 \n" +
            " and (6371 * acos(  cos(radians(b.lat)) * cos(radians(#{lat})) *  cos(radians(b.lng) - radians(#{lng})) +   sin(radians(b.lat)) * sin(radians(#{lat})) )) &lt; 500 \n" +
            " <when test='keyword != null and keyword != \"\"'> " +
            "  and( a.remark like concat('%',#{keyword},'%') \n" +
            "  or a.name like concat('%',#{keyword},'%') \n" +
            "  ${orConditions} )\n" +
            " </when> " +
            " </script>"})
    Integer selectMyStaffShopGoodsTotal(@Param("lat") Double lat, @Param("lng") Double lng, @Param("keyword") String keyword,@Param("orConditions") String orConditions);

    @Select({" <script> select a.*,b.title staff_title,b.logo staff_logo,b.headimgurl staff_headimgurl" +
            " from my_staff_shop_goods a " +
            " left join my_staff b on a.staff_id = b.id \n" +
            "<where>"+
            " and a.status =1 \n" +
            " and a.shopId = 0 \n" +
            " <if test='districtid != null and districtid != \"\"'> " +
            " and b.districtid2 = #{districtid} \n" +
            " </if> " +
            " <if test='orConditions != null and orConditions != \"\"'> " +
            "  and( ${orConditions} )\n" +
            " </if> " +
            "</where>"+
            " <if test='orderStr != null and orderStr != \"\"'> " +
            "  ${orderStr} \n" +
            " </if> " +
            " LIMIT #{page},#{pageSize} " +
            " </script>"})
    List<MyStaffShopGoodsDto> selectMyStaffShopGoodsNoLatPage(@Param("page") Long page, @Param("pageSize") Long pageSize,@Param("districtid") Integer districtid,@Param("orderStr") String orderStr,@Param("orConditions") String orConditions);

    @Select({" <script> select count(*) " +
            " from my_staff_shop_goods a " +
            " left join my_staff b on a.staff_id = b.id \n" +
            " where a.status =1 \n" +
            " and a.shopId = 0 \n" +
            " <when test='districtid != null and districtid != \"\"'> " +
            " and b.districtid2 = #{districtid} \n" +
            " </when> " +
            " <when test='orConditions != null and orConditions != \"\"'> " +
            " and ( ${orConditions} )\n" +
            " </when> " +
            " </script>"})
    Integer selectMyStaffShopGoodsNoLatTotal(@Param("districtid") Integer districtid, @Param("orConditions") String orConditions);




    @Select({" <script> select a.*,b.title staff_title,b.logo staff_logo,b.headimgurl staff_headimgurl" +
            " from my_staff_shop_goods a " +
            " left join my_staff b on a.staff_id = b.id \n" +
            "<where>"+
            " and a.status =1 \n" +
            " and a.shopId = 0 \n" +
            " <if test='districtid != null and districtid != \"\" and districtid &gt; 100000'> " +
            "  and b.districtid = #{districtid} \n" +
            " </if> " +
            " <if test='districtid != null and districtid != \"\" and districtid &lt; 100000 and districtid &gt; 1000'> " +
            "  and b.districtid1 = #{districtid} \n" +
            " </if> " +
            " <if test='districtid != null and districtid != \"\" and districtid &lt; 1000 and districtid &gt; 0'> " +
            "  and b.districtid2 = #{districtid} \n" +
            " </if> " +
            "</where>"+
            " <if test='rand != null and rand != \"\"'> " +
            "  order by rand(#{rand}) \n" +
            " </if> " +
            " LIMIT #{page},#{pageSize} " +
            " </script>"})
    List<MyStaffShopGoodsDto> selectMyStaffShopGoodsList(@Param("page") Long page, @Param("pageSize") Long pageSize, @Param("districtid") Integer districtid, @Param("rand") Integer rand);

    @Select({" <script> select count(*) " +
            " from my_staff_shop_goods a " +
            " left join my_staff b on a.staff_id = b.id \n" +
            "<where>"+
            " and a.status =1 \n" +
            " and a.shopId = 0 \n" +
            " <if test='districtid != null and districtid != \"\" and districtid &gt; 100000'> " +
            "  and b.districtid = #{districtid} \n" +
            " </if> " +
            " <if test='districtid != null and districtid != \"\" and districtid &lt; 100000 and districtid &gt; 1000'> " +
            "  and b.districtid1 = #{districtid} \n" +
            " </if> " +
            " <if test='districtid != null and districtid != \"\" and districtid &lt; 1000 and districtid &gt; 0'> " +
            "  and b.districtid2 = #{districtid} \n" +
            " </if> " +
            "</where>"+
            " </script>"})
    Integer selectMyStaffShopGoodsListTotal(@Param("districtid") Integer districtid);



}
